﻿using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using Framework.Extensions;

namespace Framework.UnitTest.Extensions
{
    [TestFixture]
    public class EnumerableExtensionsFixture
    {
        [Test]
        public void CastEnumerablesWithoutAStaticallyKnownType()
        {
            var objectList = new ArrayList {"Line 1", "Line 2"};
            var stringList = objectList.Cast(typeof (string));

            Assert.IsTrue(typeof(IEnumerable<string>).IsAssignableFrom(stringList.GetType()));
        }

        [Test]
        public void CreateListFromEnumerablesWithoutAStaticallyKnownType()
        {
            var objectList = new ArrayList {"Line 1", "Line 2"};
            var stringList = objectList.ToListOfType(typeof (string));

            Assert.IsTrue(typeof(List<string>).IsAssignableFrom(stringList.GetType()));
        }

        [Test]
        public void ReturnMinimumElementFromListWithSelector()
        {
            var items = new[] {new EnumerableTestData {Value = 5}, new EnumerableTestData {Value = 1}, new EnumerableTestData {Value = 10}};
            EnumerableTestData element = items.Minimum(testData => testData.Value);

            Assert.AreEqual(1, element.Value);
        }
    }

    public class EnumerableTestData
    {
        public int Value { get; set; }
    }
}